#!/bin/bash

 Step 1 拉取最新组件库版本
echo "Step 1: Executing publish.sh script..."
echo "Step 1: 删除现有组件库...."
rm -rf ./public/cpas-business
echo "Step 1: 删除现有组件库成功...."

echo "Step 1: 拉取最新组件库版本中...."
cpas-cli latest business:dev
echo "Step 1: 拉取最新组件库版本成功"

Step 2
echo "Step 2: 打包audit中..."

echo "Step 2: 拉取Audit最新代码...."
git pull
echo "Step 2: 拉取Audit完毕....开始build Audit"
#rm -rf ./public/cpas-business
#cp -rf ../cpas-lib-business/cpas-business ./public
npm run auditBuild
echo "audit项目打包完毕"

#if [ $1 -eq 'git' ]
#then
#   echo "git logic"
#else
#   # 还原audit
#   rm -rf ../cpas-lib-business/cpas-business
#   mv ../cpas-lib-business/cpas-business-auto-bak ../cpas-lib-business/cpas-business
#fi

# Step 3
echo "Step 3: audit包导入到freamwork中..."
cd ../framework
git pull
if [ $1 -eq 'git' ]
then
   rm -rf ./webapps/cpas-cloud/audit
else
   # 先重名名再拷贝
   mv ./webapps/cpas-cloud/audit ./webapps/cpas-cloud/audit-auto-bak
fi

cp -rf ../cpas-workplatform-audit/audit ./webapps/cpas-cloud
echo "audit包导入到freamwork中完毕"

# Step 4
echo "Step 4: 打包增量包中..."
npm run cpas6-release
echo "打包增量包完毕"

if [ $1 -eq 'git' ]
then
   echo "git logic"
else
   rm -rf ./webapps/cpas-cloud/audit
   # 还原audit
   mv ./webapps/cpas-cloud/audit-auto-bak ./webapps/cpas-cloud/audit
fi

echo "整体打包完成"
